﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TestDataCreator
{
	/// <summary>
	/// This class contains a "image path";"License plate number" set
	/// It can be used for batch testing (comparison)
	/// </summary>
	public class DataItem : ICloneable
	{
		/// <summary>
		/// Specifies a full path to an image or a video file
		/// </summary>
		private string imagePath;
		public string ImagePath
		{
			get { return imagePath; }
			set { imagePath = value; }
		}

		/// <summary>
		/// Specicifes a license plate number of a car
		/// </summary>
		private string licenseNumber;
		public string LicenseNumber
		{
			get { return licenseNumber; }
			set { licenseNumber = value; }
		}

		/// <summary>
		/// Specifies if the file is a movie/video
		/// </summary>
		private bool isVideo;
		public bool IsVideo
		{
			get { return isVideo; }
			set { isVideo = value; }
		}
		/// <summary>
		/// The default consctructor
		/// </summary>
		public DataItem()
		{
			// Can be kept empty
		}
		
		/// <summary>
		/// The constructor that initializes all attributes
		/// </summary>
		/// <param name="path">Image path</param>
		/// <param name="number">License plate number</param>
		/// <param name="_isVideo">Is it a video file?</param>
		public DataItem(string path, string number, bool _isVideo)
		{
			this.licenseNumber = number;
			this.imagePath = path;
			this.isVideo = _isVideo;
		}
		
		/// <summary>
		/// The constructor which allows to initialize the attributes with a string array
		/// </summary>
		/// <param name="rows">A string array with all class attributes: {imagePath, licenseNumber, isVideo}</param>
		public DataItem(string[] rows)
		{
			this.imagePath = rows[0].Trim();
			this.licenseNumber = rows[1].Trim();			
			this.isVideo = Boolean.Parse(rows[2].Trim());
		}

		/// <summary>
		/// Returns a System.String that represents current object
		/// </summary>
		/// <returns>A String that represents the current object</returns>
		public override string ToString()
		{
			return String.Format(string.Format("{0};{1};{2}", this.imagePath, this.licenseNumber, this.isVideo.ToString()));
		}

		/// <summary>
		/// Returns a System.String that represents current object
		/// </summary>
		/// <param name="relativeToPath">Convert all image/video paths to be relative towards the specified path</param>
		/// <returns>A String that represents the current object</returns>
		public string ToString(string relativeToPath)
		{
			return String.Format(string.Format("{0};{1};{2}", this.imagePath.Replace((relativeToPath + @"\"), string.Empty), this.licenseNumber, this.isVideo.ToString()));
		}

		/// <summary>
		/// Creates a new DataItem object that is a copy of the current instance
		/// </summary>
		/// <returns>A new DataItem object that is a copy of this instance</returns>
		public object Clone()
		{
			DataItem clonedObj = new DataItem();
			clonedObj.imagePath = this.imagePath;
			clonedObj.licenseNumber = this.licenseNumber;
			clonedObj.isVideo = this.isVideo;
			return clonedObj;
		}

		/// <summary>
		/// Allows to get a short file name instead of a full path
		/// </summary>
		/// <returns>Short file name</returns>
		public string GetFileName()
		{
			return System.IO.Path.GetFileName(this.imagePath);
		}
	}
}
